#!/bin/sh
#
# {{ ansible_managed }}

# Name of the environment for this deploy
m_environment="{{ env }}"

### DIRECTORY STRUCTURE ###

# meza install location
m_install="{{ m_install }}"
m_meza="{{ m_meza }}"

m_config_core="{{ m_config_core }}"
m_scripts="{{ m_scripts }}"
m_test="{{ m_test }}"
m_tmp="{{ m_tmp }}"

# data dir
m_meza_data="{{ m_meza_data }}"
m_uploads_dir="{{ m_uploads_dir }}"
m_logs="{{ m_logs }}"

m_backups="{{ m_backups }}"
allow_backup_downloads='{{ allow_backup_downloads }}'

# Things deployed by ansible
m_deploy='{{ m_deploy }}'

# webserver variables
m_htdocs="{{ m_htdocs }}"
m_mediawiki="{{ m_mediawiki }}"

# app locations
m_apache="{{ m_apache }}"

### DATABASE DATA AND CREDENTIALS ###
db_master="{{ groups['db_master'][0] }}"
wiki_app_db_user_name='{{ wiki_app_db_user.name }}'
wiki_app_db_user_pass='{{ wiki_app_db_user.password }}'

# Replication
m_db_replication_dump_file="{{ m_db_replication_dump_file }}"
m_db_replication_log_file="{{ m_db_replication_log_file }}"
m_db_replication_log_pos="{{ m_db_replication_log_pos }}"

### LANGUAGE ###
m_language="{{ m_language }}"
m_i18n="{{ m_i18n }}"



#
# DEPLOY VARS included in the following order, with each superceding the previous
#   1. public
#   2. env-specific
#   3. secret
#   4. FIXME: deprecated deploy_vars, use secret_deploy_vars instead
#

{% if public_deploy_vars is defined and public_deploy_vars is iterable %}
#
# CUSTOM __public__ DEPLOY VARIABLES
# These should only come from public.yml
#
{% for key, value in public_deploy_vars.items() %}
{% if value is string %}
{{ key }}="{{ value }}"
{% elif value is iterable %}
# Skipping iterable deploy var {{ key }}. FIXME #856.
{% else %}
{{ key }}="{{ value }}"
{% endif %}
{% endfor %}
{% endif %}


{% if env_deploy_vars is defined and env_deploy_vars is iterable %}
#
# CUSTOM __{{ env }} environment__ DEPLOY VARIABLES
# These should only come from env/{{ env }}.yml
#
{% for key, value in env_deploy_vars.items() %}
{% if value is string %}
{{ key }}="{{ value }}"
{% elif value is iterable %}
# Skipping iterable deploy var {{ key }}. FIXME #856.
{% else %}
{{ key }}="{{ value }}"
{% endif %}
{% endfor %}
{% endif %}


{% if secret_deploy_vars is defined and secret_deploy_vars is iterable %}
#
# CUSTOM __secret__ DEPLOY VARIABLES
# These should only come from secret.yml
#
{% for key, value in secret_deploy_vars.items() %}
{% if value is string %}
{{ key }}="{{ value }}"
{% elif value is iterable %}
# Skipping iterable deploy var {{ key }}. FIXME #856.
{% else %}
{{ key }}="{{ value }}"
{% endif %}
{% endfor %}
{% endif %}


{% if deploy_vars is defined and deploy_vars is iterable %}
#
# __DEPRECATED__ CUSTOM DEPLOY VARIABLES
#
# FIXME: remove deploy_vars in lieu of secret_deploy_vars when production wikis
#        are updated.
#
{% for key, value in deploy_vars.items() %}
{% if value is string %}
{{ key }}="{{ value }}"
{% elif value is iterable %}
# Skipping iterable deploy var {{ key }}. FIXME #856.
{% else %}
{{ key }}="{{ value }}"
{% endif %}
{% endfor %}
{% endif %}



#
# SERVER PERFORMANCE
#
{% if slack_channel_server_performance is defined %}
# Slack channel to send server performance info. If undefined, will use webhook default
slack_channel_server_performance="{{ slack_channel_server_performance }}"
{% endif %}

{% if slack_webhook_token_server_performance is defined %}
# Slack incoming webhook token for sending server performance info
slack_webhook_token_server_performance="{{ slack_webhook_token_server_performance }}"
{% endif %}

{% if slack_username_server_performance is defined %}
# Slack username to display for webhook
slack_username_server_performance="{{ slack_username_server_performance }}"
{% endif %}


#
# DISK USAGE
#
{% if disk_space_usage_mount_name is defined %}
disk_space_usage_mount_name="{{ disk_space_usage_mount_name }}"
{% endif %}

# A short name used in description when sending Slack message
disk_space_usage_mount_short_name="{{ disk_space_usage_mount_short_name | default('Disk') }}"

{% if slack_channel_disk_usage is defined %}
# Slack channel to send disk usage info. If undefined, will use webhook default
slack_channel_disk_usage="{{ slack_channel_disk_usage }}"
{% endif %}

{% if slack_webhook_token_disk_usage is defined %}
# Slack incoming webhook token for sending disk usage info
slack_webhook_token_disk_usage="{{ slack_webhook_token_disk_usage }}"
{% endif %}

{% if slack_username_disk_usage is defined %}
# Slack username to display for webhook
slack_username_disk_usage="{{ slack_username_disk_usage }}"
{% endif %}



#
# Auto-deployer
#
{% if secret_config_repo is defined and secret_config_repo.repo is defined %}
# Info about local public config
secret_config_repo_repo="{{ secret_config_repo.repo }}"
secret_config_repo_version="{{ secret_config_repo.version | default('master') }}"
secret_config_repo_force="{{ secret_config_repo.force | default(false) | bool }}"
{% endif %}

{% if local_config_repo is defined and local_config_repo.repo is defined %}
# Info about local public config
local_config_repo_repo="{{ local_config_repo.repo }}"
local_config_repo_version="{{ local_config_repo.version | default('master') }}"
local_config_repo_force="{{ local_config_repo.force | default(false) | bool }}"
{% endif %}

{% if enforce_meza_version is defined %}
# What Meza version to track
enforce_meza_version="{{ enforce_meza_version }}"
{% endif %}

{% if autodeployer is defined %}
{% if autodeployer.slack_channel is defined %}
autodeployer_slack_channel="{{ autodeployer.slack_channel }}"
{% endif %}

{% if autodeployer.slack_token is defined %}
autodeployer_slack_token="{{ autodeployer.slack_token }}"
{% endif %}

{% if autodeployer.slack_username is defined %}
autodeployer_slack_username="{{ autodeployer.slack_username }}"
{% endif %}

{% if autodeployer.slack_icon_url is defined %}
autodeployer_slack_icon_url="{{ autodeployer.slack_icon_url }}"
{% endif %}
{% endif %}

